package com.cooper.moviedb.servers;

import com.cooper.moviedb.bo.MediaEntity;
import org.hibernate.Session;
import org.hibernate.SessionFactory;

import java.util.List;

/**
 * Created with IntelliJ IDEA.
 * User: cooperlee
 * Date: 11/14/12
 * Time: 4:44 PM
 * To change this template use File | Settings | File Templates.
 */
public class ServicesDao {

    public void setSessionFactory(SessionFactory sessionFactory) {
        this.sessionFactory = sessionFactory;
    }

    private SessionFactory sessionFactory;

    public ServicesDao() {

    }

    public ServicesDao(SessionFactory sessionFactory) {
        this.sessionFactory = sessionFactory;
    }

    public List<MediaEntity> getAllMedia() {
        Session session = sessionFactory.openSession();
        // Transaction tx= session.beginTransaction();
        // tx.commit();

        return session.createQuery("from MediaEntity").list();
        // session.close();
    }
}
